<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">维修</block>
			</cu-custom>
			<!-- 查询条件 -->
			<view class="fixed" :style="[{animationDelay: 0.1 + 's'}]">
				<form>
					<view class="cu-form-group last">
						<image class="icon" src="../../static/saomiao.png" mode=""></image>
						<input auto-focus placeholder="请扫描条码" name="input" v-model="correspondingBarcode" @confirm="inputQuery"></input>
						<view class="btns" v-if="type === 'yzy'">
							<view class="btn1" @click="goPage({})">新增</view>
						</view>
					</view>
				</form>
			</view>
			<!-- 数据列表 -->
			<view class="list" v-if="type === 'zs'">
				<view class="card animation-slide-bottom" v-for="(item,index) in list" :key="index" :style="[{animationDelay: (index + 1)*0.1 + 's'}]">
					<view class="top">
						<view class="left">制令单号：<text>{{item.commandbillCode}}</text></view>
					</view>
					<view class="line">

					</view>
					<view class="bottom">
						<view class="box">
							<view class="lable">
								客户编码:
							</view>
							<view class="content">
								{{item.customerCode}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								集研编码:
							</view>
							<view class="content">
								{{item.researchCode}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								测试工位:
							</view>
							<view class="content">
								{{item.testStation}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								发生日期:
							</view>
							<view class="content">
								{{item.happenDate}}
							</view>
						</view>
						<view class="box" v-if="item.retestPersonnel">
							<view class="lable">
								测试人员:
							</view>
							<view class="content">
								{{item.retestPersonnel}}
							</view>
						</view>
						<view class="box" v-if="!item.retestPersonnel">
							<view class="lable">
								测试人员:
							</view>
							<view class="content">
								{{item.firstTestPersonnel}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								对应条码:
							</view>
							<view class="content">
								{{item.correspondingBarcode}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								不合格现象:
							</view>
							<view class="content">
								{{item.unqualifiedPhenomenon}}
							</view>
						</view>

					</view>
					<view class="line">

					</view>
					<view class="btns">
						<view class="btn1" @click="goPage(item)">维修完成</view>
					</view>
				</view>
			</view>
			<view class="list" v-else>
				<view class="card animation-slide-bottom" v-for="(item,index) in list" :key="index" :style="[{animationDelay: (index + 1)*0.1 + 's'}]">
					<view class="top">
						<view class="left">制令单号：<text>{{item.commandbillCode}}</text></view>
					</view>
					<view class="line">

					</view>
					<view class="bottom">
						<view class="box">
							<view class="lable">
								班别:
							</view>
							<view class="content">
								{{item.classType}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								线别:
							</view>
							<view class="content">
								{{item.lineType}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								站别:
							</view>
							<view class="content">
								{{item.standType}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								机型:
							</view>
							<view class="content">
								{{item.model}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								不良数量:
							</view>
							<view class="content">
								{{item.badQuantity}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								日期:
							</view>
							<view class="content">
								{{item.happenDate}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								SN:
							</view>
							<view class="content">
								{{item.correspondingBarcode}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								不良现象:
							</view>
							<view class="content">
								{{item.unqualifiedReason}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								维修位置:
							</view>
							<view class="content">
								{{item.repairProgramme}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								备注:
							</view>
							<view class="content">
								{{item.query1}}
							</view>
						</view>
					</view>
					<!-- <view class="line">

					</view>
					<view class="btns">
						<view class="btn1" @click="goPage(item)">维修完成</view>
					</view> -->
				</view>
			</view>
			<view class="none" v-if="noDataAvailable">
				<view class="none1">
					暂无数据
				</view>
			</view>
			<view class="none2" v-if="noMoreDataAvailable">
				没有更多数据
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name: 'zsTest',
		data() {
			return {
				TabCur: 0,
				tabNav: ['SMT', 'DIP'],
				myFormData: {
					oddNumber: ''
				},
				list: [],
				isCard: true,
				pageNo: 1,
				noDataAvailable: false,
				noMoreDataAvailable: false,
				statusList: [], // 备注伸展状态
				correspondingBarcode:'',
				type:'yzy',
			}
		},
		onLoad(e) {
			this.type = 'zs'
			uni.$on('updateRepair',(res)=>{
				this.pageNo = 1
				this.list = []
				this.getMesCommandbillInfoList();
			})
			this.pageNo = 1
			this.list = []
			this.getMesCommandbillInfoList();
		},
		onPullDownRefresh: function() {
			let _this = this

			setTimeout(function() {
				uni.stopPullDownRefresh();
				_this.getMesCommandbillInfoList()
			}, 1000);
		},
		onReachBottom: function() {
			let _this = this
			if (this.noDataAvailable == true || this.noMoreDataAvailable == true) {
				return
			}
			_this.pageNo++
			_this.getMesCommandbillInfoList()
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.getMesCommandbillInfoList();
			},
			goPage(item) {
				let page = 'testList'
				this.$Router.push({
					name: 'repairComplete',
					params:{
						id:item.id,
						repairType:this.type
					}
				})
			},
			// 制造中心-制令单信息-分页列表查询
			getMesCommandbillInfoList() {
				uni.showLoading({
					mask:true,
					title:'加载中.....'
				})
				this.noDataAvailable = false
				this.noMoreDataAvailable = false
				let data = {
					type:this.type === 'yzy' ? 'repair_yzy' : 'repair_zs',
					pageNo: this.pageNo,
					pageSize: 10000,
					correspondingBarcode:this.correspondingBarcode,
					commandbillCode: this.myFormData.oddNumber,
					// firstState: '未完成',
					controlType:'正常',
					status:this.type === 'yzy' ? 'confirm_complete' : 'waiting_repair',
					// deliveryState: '已完成',
					produceGrade: this.tabNav[this.TabCur]
				}
				let _this = this
				this.$http.get('inspect/zsUnqualifiedRepairCard/list', {
					params: data
				}).then(res => {
					uni.hideLoading()
					if (res.data.success) {
						// _this.list = _this.list.concat(res.data.result.records);
						_this.list = res.data.result.records;
						_this.statusList = []
						for (let i = 0; i < _this.list.length; i++) {
							_this.statusList.push(false)
						}
						_this.preservationList = []
						for (let i = 0; i < _this.list.length; i++) {
							let data = {
								id: _this.list[i].id,
								num: ''
							}
							_this.preservationList.push(data)
						}
						if (_this.list.length == 0) {
							_this.noDataAvailable = true;
						} else if (_this.list.length > 0 && res.data.result.records.length == 0) {
							_this.noMoreDataAvailable = true;
						} else if (res.data.result.total <= _this.list.length) {
							_this.noMoreDataAvailable = true;
						}
						console.log(_this.list)
					} else {
						// _this.$tip.error(res.data.message)
            _this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			// 输入框查询
			inputQuery() {
				console.log(this.myFormData.oddNumber)
				this.pageNo = 1;
				this.list = [];
				this.getMesCommandbillInfoList();
			},
			// 备注展开
			showNote(index) {
				this.$set(this.statusList, index, !this.statusList[index]);
				console.log(this.statusList[index])
			}
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f1f1f1;

		.fixed {
			position: fixed;
			z-index: 1;
			width: 100%;
			background-color: white;
			height: 100rpx;
			border-bottom: 1rpx solid #eee;

			.last {
				border-bottom: 1rpx solid #eee;
				position: relative;

				.icon {
					width: 30rpx;
					height: 29rpx;
					position: absolute;
					top: 36rpx;
					left: 60rpx;
				}

				input {
					width: 686rpx;
					height: 68rpx;
					background: #FFFFFF;
					border: 1px solid #D5D8DF;
					border-radius: 34px;
					padding-left: 79rpx;
				}
			}
		}

		.list {
			margin-top: 120rpx;

			.card {
				margin: 30rpx;
				box-shadow: 0px 0px 5rpx 2rpx rgba(0, 0, 0, 0.1);
				border-radius: 10rpx;
				background-color: white;

				.top {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-weight: bold;
					padding: 20rpx 30rpx;

					.left {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #485A75;
						line-height: 50rpx;
					}

					.right {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #191919;
						line-height: 50rpx;
					}
				}

				.line {
					width: 750rpx;
					height: 10rpx;
					background: #F3F5F9;
				}

				.bottom {
					padding: 20rpx 30rpx;

					.box {
						display: flex;
						justify-content: space-between;
						padding: 20rpx 0;
						align-items: center;

						.lable {
							color: #485A75;
							font-size: 28rpx;
						}

						.content {
							width: 70%;
							text-align: right;
							color: #191919;
							font-weight: bold;
							word-break: break-all;
						}

						.shrink {
							height: 40rpx;
							overflow: hidden;
							white-space: nowrap;
							/*不换行*/
							text-overflow: ellipsis;
							/*超出部分文字以...显示*/
							font-weight: 400;
						}

						.unfold {
							text-align: left;
							font-weight: 400;
						}
					}
				}


			}
		}
	}
.btns {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;
					font-size: 25rpx;
					padding: 20rpx 30rpx;

					view {
						width: 180rpx;
						height: 64rpx;
						line-height: 50rpx;
						color: white;
						border-radius: 30rpx;
						padding: 10rpx 20rpx;
						text-align: center;
					}

					.btn1 {
						// margin-left: 450rpx;
						background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
					}
				}
	.none .none1 {
		font-size: 30rpx;
		text-align: center;
		margin-top: 50rpx;
		color: #999999;
	}

	.none2 {
		font-size: 30rpx;
		text-align: center;
		margin-top: 50rpx;
		color: #999999;
	}

</style>
